$(function(){
      $(".header").load("header.html");$(".footer").load("footer.html"); 
    });
    
    var myModule = angular.module('myModule', []);

    myModule.controller('MyController', function ($scope, $http,$location) {
    	$scope.subjectItems = [];
    	
    	
        $scope.items = [];
    	$scope.noticeitems=[];
    	
    	$scope.options = [
    	  {option:'제목', title:'title',number:0},
    	  {option:'내용', title:'content',number:1},
    	  {option:'제목+내용',title:'titleContent',number:2},
    	  {option:'작성자',title:'writer',number:3} 
    	];
    	
    	
    	$scope.title = $scope.options[$location.search().title==null ? 0 : $location.search().title];

        $scope.currentPageitems = [];
        $scope.currentPage = 1;
        $scope.pages = [];
        $scope.pagePrev = 0;
        $scope.pageNext = 0;
        $scope.pageSize = 5;

		
		$scope.presentSearch='';
		$scope.user='';
		
		
		$scope.search='';
		
		if($location.search().pg!=null){
    		$scope.currentPage=$location.search().pg;

    		$scope.search=$location.search().search;
    	}
        
        $scope.go = function(content_id) {
        	location.href='QnA_board.html#?content_id='+content_id+"&pg="+$scope.currentPage+"&title="+$scope.title.number+ "&search="+$scope.presentSearch;
       }
        
        $scope.gotoPage = function(page) {
            $scope.currentPage = page;
        	var pageCount= Math.ceil($scope.items.length * 1.0 / $scope.pageSize);
        	var pageBase = Math.floor(($scope.currentPage - 1) / 10) * 10;
        	$scope.pages = [];
            for (var i = 1; i <= 10 && pageBase + i <= pageCount; ++i)
                $scope.pages.push(pageBase + i);
            if (pageBase > 0) $scope.pagePrev = pageBase; else delete $scope.pagePrev;
            if (pageBase + 11 < pageCount) $scope.pageNext = pageBase + 11; else delete $scope.pageNext;

        	$scope.currentPageitems = [];
        	for (var i = 0; i < $scope.pageSize; ++i) {
        		var n = ($scope.currentPage - 1) * $scope.pageSize + i;
        		if (n >= $scope.items.length) break;
        		$scope.currentPageitems.push($scope.items[n]);    		
        	}
        } 
        
        $scope.loadNotice = function() {
        	myUtil.onHttp($http,'get','loadNotice.do',{board_id:2},null,function(data) {$scope.noticeitems=data});
        }
        
        $scope.loadData = function() {

        	myUtil.onHttp($http,'get','notice.do',{ str: $scope.search ,temp : $scope.title.title , board_id : 2,subject_id : ''},null,
        			function(data){$scope.items = data; $scope.gotoPage($scope.currentPage);})
        			
        	
        }
 
      
        $scope.searchTitle = function(){
        	$scope.currentPage=1;	
        	$scope.presentSearch=$scope.search;
        	$scope.loadData();
        	
        }
        $scope.loadNotice();
        $scope.loadData();
        
        
        
    });